package com.guigu.www.service.impl;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.guigu.www.dao.bean.Employee;
import com.guigu.www.dao.mapper.DeptMapper;
import com.guigu.www.dao.mapper.EmployeeMapper;
import com.guigu.www.service.EmployeeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.guigu.www.service.pojo.EmployeeAndDept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author WangChenZhen
 * @since 2021-03-17
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {

    @Autowired
    DeptMapper deptMapper;
    @Autowired
    EmployeeMapper employeeMapper;


    public Page<EmployeeAndDept> query(Page<Employee> page, Wrapper<Employee> wrapper) {
        Page<EmployeeAndDept> pageEAD=new Page<EmployeeAndDept>();
        Page<Employee> pageE=this.selectPage(page,wrapper);

        List<EmployeeAndDept> list=new ArrayList<EmployeeAndDept>();
        for(Employee e : pageE.getRecords()){
            list.add(new EmployeeAndDept(e,deptMapper.selectById(e.getDeptno())));
        }

        pageEAD.setCurrent(pageE.getCurrent());
        pageEAD.setSize(pageE.getSize());
        pageEAD.setRecords(list);
        pageEAD.setTotal(pageE.getTotal());
        return pageEAD;
    }
}
